package cn.dengta.webapp.trade.entity;

import java.math.BigDecimal;
import java.util.Date;
import java.util.function.Function;

import cn.dengta.context.model.Option;
import cn.dengta.webapp.base.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 提现支持的银行配置
 *
 * @author xy
 * @since 2022-08-12
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("tr_cash_bank")
public class CashBank extends BaseEntity {

	private static final long serialVersionUID = 1L;
	/** 国家 */
	private String country;
	/** 1=payermax */
	private Integer type;
	/** 银行编码 */
	private String bankCode;
	/** 银行名称 */
	private String bankName;
	/** 币种 */
	private String currency;
	/** 支付方式 */
	private String payMethod;
	/** 支持的最小值 */
	private BigDecimal minValue;
	/** 支持的最大值 */
	private BigDecimal maxValue;
	/** 图标 */
	private String icon;
	/** 是否可用： -1=不可用；1=可用 */
	private Integer status;
	/** 添加时间 */
	private Date addTime;
	/** 更新时间 */
	private Date updateTime;

	public static final String COUNTRY = "country";
	public static final String TYPE = "type";
	public static final String BANK_CODE = "bank_code";
	public static final String BANK_NAME = "bank_name";
	public static final String CURRENCY = "currency";
	public static final String PAY_METHOD = "pay_method";
	public static final String MIN_VALUE = "min_value";
	public static final String MAX_VALUE = "max_value";
	public static final String ICON = "icon";
	public static final String STATUS = "status";
	public static final String ADD_TIME = "add_time";
	public static final String UPDATE_TIME = "update_time";

	public boolean checkAmount(BigDecimal amount) {
		boolean check = true;
		if (this.minValue != null) {
			check = this.minValue.compareTo(amount) < 0;
		}
		if (check && this.maxValue != null) {
			check = amount.compareTo(this.maxValue) < 0;
		}
		return check;
	}

	public Option<String> toOption() {
		Function<CashBank, Option<String>> f = Option.converter(CashBank::getBankCode, CashBank::getBankCode);
		return f.apply(this);
	}

}
